package cn.linlane.entity.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@MappedSuperclass
@JsonIgnoreProperties(value = {"hibernateLazyInitializer","handler","fieldHandler"})
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    protected Long id;

    /**
     * 创建时间
     */
    @JsonIgnore
    @CreatedDate
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间 yyyyMMdd hh:mm:ss")
    protected Date createTime;

    /**
     * 创建人
     */
    @JsonIgnore
    @CreatedBy
    @Column(name = "create_by")
    @ApiModelProperty(value = "创建人ID")
    protected Long createBy;

    /**
     * 更新时间
     */
    @JsonIgnore
    @LastModifiedDate
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间 yyyyMMdd hh:mm:ss")
    protected Date updateTime;

    /**
     * 更新人
     */
    @JsonIgnore
    @LastModifiedBy
    @Column(name = "update_by")
    @ApiModelProperty(value = "更新人ID")
    protected Long updateBy;

    @JsonIgnore
    @Column(name = "is_delete")
    @ApiModelProperty(value = "是否刪除 false：否，true：是")
    protected boolean isDelete = false;

    @JsonIgnore
    @ApiModelProperty(hidden = true)
    public void setDelete(boolean delete) {
        isDelete = delete;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Long getCreateBy() {
        return createBy;
    }

    public void setCreateBy(Long createBy) {
        this.createBy = createBy;
    }

    public Long getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(Long updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public boolean isDelete() {
        return isDelete;
    }
}
